<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        var time = 1511851696000
		
        function getDate(time) {
            var date = new Date(time)
            var now = Date.parse(new Date())
            // 跨年
            if (date.getFullYear() != new Date().getFullYear()) {
                var year = date.getFullYear()
                var month = date.getMonth() + 1
                var day = date.getDate()
                return {
                    "year": year,
                    "month": month,
                    "day": day
                }
            } else {
                // 说明在今天(当天)
                if (now - time < 86400000) {
                    var hours = date.getHours()
                    var minutes = date.getMinutes()
                    return {
                        "hours": hours,
                        "minutes": minutes
                    }
                }
                // 说明不是今天(跨天)
                if (now - time > 86400000) {
                    var month = date.getMonth() + 1
                    var day = date.getDate()
                    return {
                        "month": month,
                        "day": day
                    }
                }
            }
        }

        console.log(getDate(new Date().getTime()))
        console.log(getDate(time))
    </script>
</body>

</html>